package com.qsmx.store.app.main.mem;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.qsmx.store.app.R;
import com.qsmx.store.app.R2;
import com.qsmx.store.app.main.adapter.TabPagerAdapter;
import com.qsmx.store.app.main.home.HomeDelegate;
import com.qsmx.store.core.delegates.AtmosDelegate;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MemInfoResetDelegate extends AtmosDelegate {

    String[] titles = new String[]{"基础修改", "特殊修改", "密码修改"};

    @BindView(R2.id.tl_mem_info_reset)
    TabLayout tlMemInfoReset = null;
    @BindView(R2.id.vp_mem_info_reset)
    ViewPager vpMemInfoReset = null;

    @OnClick(R2.id.iv_back)
    void onBack() {
        getParentDelegate().getSupportDelegate().pop();
    }

    @OnClick(R2.id.iv_home)
    void onHome() {
        getParentDelegate().getSupportDelegate().popTo(HomeDelegate.class, false);
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_mem_info_reset;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {

        initTab();

    }

    private void initTab() {

        List<Fragment> fragmentList = new ArrayList<>();

        MemInfoBaseResetDelegate delegate = new MemInfoBaseResetDelegate();
        MemInfoSpecialResetDelegate delegate1 = new MemInfoSpecialResetDelegate();
        MemInfoPasswordResetDelegate delegate2 = new MemInfoPasswordResetDelegate();

        fragmentList.add(delegate);
        fragmentList.add(delegate1);
        fragmentList.add(delegate2);

        TabPagerAdapter tabPagerAdapter = new TabPagerAdapter(getChildFragmentManager(), fragmentList, titles);
        vpMemInfoReset.setAdapter(tabPagerAdapter);
        vpMemInfoReset.setOffscreenPageLimit(0);
        tlMemInfoReset.setupWithViewPager(vpMemInfoReset);
    }

}
